package acwing;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing.QuestionsPractice
 * @File : Q4942.java
 * @Author : WangRuoyu
 * @Date : 2023/4/2 19:13
 */

import java.io.*;

public class Q4942 {
    static int n;
    static int m;

    static boolean check() {
        if (n == 2) {
            return true;
        }
        while (m != 0) {
            int mod = m % n;
            if (mod != 0 && mod != 1 && mod != n - 1) {
                return false;
            }
            if (mod == n - 1) mod = -1;

            m = (m - mod) / n;
        }
        return true;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] words = br.readLine().split(" ");
        n = Integer.parseInt(words[0]);
        m = Integer.parseInt(words[1]);

        if (check()) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

// dfs 暴搜 TLE
//public class Q4942 {
//    static long n;
//    static long m;
//    static int k = 1;
//    static long[] oj = new long[110];
//
//    static boolean dfs(int x, long sum) {
//        if (x > k || sum > m) {
//            return false;
//        } else if (sum == m) {
//            return true;
//        } else {
//            return dfs(x + 1, sum - oj[x]) || dfs(x + 1, sum) || dfs(x + 1, sum + oj[x]);
//        }
//    }
//
//    public static void main(String[] args) throws IOException {
//        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        String[] words = br.readLine().split(" ");
//        n = Integer.parseInt(words[0]);
//        m = Integer.parseInt(words[1]);
//        oj[0] = 1;
//        for (long s = 1; s <= n * m; ) {
//            s = 1 + s * n;
//            oj[k] = oj[k - 1] * n;
//            k++;
//        }
//        if (dfs(0, 0)) {
//            System.out.println("YES");
//        } else {
//            System.out.println("NO");
//        }
//    }
//}
